package com.example.appxi;



import java.util.Locale;







import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;

public class BannerActivity extends ParentActivity {
	View btn_newbanner;
	View btn_hotbanner;
	View btn_nearbanner;
	
	static Context mContext;
	
	TextView text_newbanner;
	TextView text_hotbanner;
	TextView text_nearbanner;

	SectionsPagerAdapter mSectionsPagerAdapter;
	ViewPager mViewPager;
	
    @SuppressLint("NewApi")
	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_banner);
        top=this;
        
        mContext = getApplicationContext();
        
        btn_newbanner=findViewById(R.id.bt_newbanner);
        btn_hotbanner=findViewById(R.id.bt_hotbanner);
        btn_nearbanner=findViewById(R.id.bt_nearbanner);
        text_newbanner=(TextView) findViewById(R.id.T_newbanner);
        text_hotbanner=(TextView) findViewById(R.id.T_hotbanner);
        text_nearbanner=(TextView) findViewById(R.id.T_nearbanner);
        // Create the adapter that will return a fragment for each of the three
     	// primary sections of the activity.
     	mSectionsPagerAdapter = new SectionsPagerAdapter(
     			getSupportFragmentManager());
     		// Set up the ViewPager with the sections adapter.
    		mViewPager = (ViewPager) findViewById(R.id.bannerpager);
    		mViewPager.setAdapter(mSectionsPagerAdapter);
    		mViewPager
			.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
				@Override
				public void onPageSelected(int position) {
					TabControll(position);
				}
			});
        LinearLayout layout = new LinearLayout(this);
        layout.post(new Runnable() {
            @Override
            public void run() {
                getStatusBarSize();
            }
        });
        TabControll(0);
        btn_newbanner.setOnClickListener(new OnClickListener()
        {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mViewPager.setCurrentItem(0, true);
			}
        	
        });
        btn_hotbanner.setOnClickListener(new OnClickListener()
        {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mViewPager.setCurrentItem(1, true);
			}
        	
        });
        btn_nearbanner.setOnClickListener(new OnClickListener()
        {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mViewPager.setCurrentItem(2, true);
			}
        	
        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        
        // Inflate the menu; this adds items to the action bar if it is present.
        //getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    public void TabControll(int position)
    {
    	String strColorOn = "#FF0000";
    	String strColorOff = "#000000";
    	switch(position)
    	{
    	case 0:
    		text_newbanner.setTextColor(Color.parseColor(strColorOn));
    		text_hotbanner.setTextColor(Color.parseColor(strColorOff));
    		text_nearbanner.setTextColor(Color.parseColor(strColorOff));
    		break;
    	case 1:
    		text_newbanner.setTextColor(Color.parseColor(strColorOff));
    		text_hotbanner.setTextColor(Color.parseColor(strColorOn));
    		text_nearbanner.setTextColor(Color.parseColor(strColorOff));
    		break;
    	case 2:
    		text_newbanner.setTextColor(Color.parseColor(strColorOff));
    		text_hotbanner.setTextColor(Color.parseColor(strColorOff));
    		text_nearbanner.setTextColor(Color.parseColor(strColorOn));
    		break;
    	}
 
    }
    
    
    public class SectionsPagerAdapter extends FragmentPagerAdapter {

		public SectionsPagerAdapter(FragmentManager fm) {
			super(fm);
		}

		@Override
		public Fragment getItem(int position) {
			// getItem is called to instantiate the fragment for the given page.
			// Return a PlaceholderFragment (defined as a static inner class
			// below).
			return PlaceholderFragment.newInstance(position + 1);
		}

		@Override
		public int getCount() {
			// Show 3 total pages.
			return 3;
		}


	}

	public static class PlaceholderFragment extends Fragment {
		/**
		 * The fragment argument representing the section number for this
		 * fragment.
		 */
		private static final String ARG_SECTION_NUMBER = "section_number";

		/**
		 * Returns a new instance of this fragment for the given section number.
		 */
		public static PlaceholderFragment newInstance(int sectionNumber) {
			PlaceholderFragment fragment = new PlaceholderFragment();
			Bundle args = new Bundle();
			args.putInt(ARG_SECTION_NUMBER, sectionNumber);
			fragment.setArguments(args);
			return fragment;
		}

		public PlaceholderFragment() {
		}

		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container,
				Bundle savedInstanceState) {
			View rootView = inflater.inflate(R.layout.frag_banner, container,
					false);
	    	LinearLayout vertiissue = (LinearLayout) rootView.findViewById(R.id.thisisbanner);
	        
	    	 LinearLayout.LayoutParams bannerParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
	    	 bannerParams.setMargins(0, 0, 0, 20);
	    	 
	    	 LinearLayout.LayoutParams firstParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, 90);
	    	 firstParams.setMargins(20, 0, 20, 0);
	    	 
	    	 LinearLayout.LayoutParams secondParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
	    	 secondParams.setMargins(20,0,20,20);
	    	 
	    	 LinearLayout.LayoutParams lastParams = new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, 90);
	    	 lastParams.setMargins(2, 0, 2, 0);
	    	 
	    	 
	    	 LinearLayout.LayoutParams firstinParams = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 10);
	    	 LinearLayout.LayoutParams firstinParams2 = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 25);
	    	 LinearLayout.LayoutParams lastinParams = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 35);
			
	    	 for(int i=0;i<=9;i++){
	    	 
	    	 int bannercolor = 0x33AA00AA;
	    	 LinearLayout actualbanner = new LinearLayout(mContext);
	    	 actualbanner.setOrientation(LinearLayout.VERTICAL);
	    	 actualbanner.setBackgroundColor(bannercolor);
	    	 actualbanner.setLayoutParams(bannerParams);
	    	 
	    	 
	    	 LinearLayout firstline = new LinearLayout(mContext);
	    	 firstline.setOrientation(LinearLayout.HORIZONTAL);
	    	 firstline.setLayoutParams(firstParams);
	    	 firstline.setGravity(Gravity.CENTER);
	    	 
	    	 

	    	 LinearLayout textview= new LinearLayout(mContext);
	   		 textview.setClickable(true);
	   		 textview.setLayoutParams(firstinParams);
	   		 textview.setOrientation(LinearLayout.VERTICAL);
	   		 textview.setGravity(Gravity.CENTER);

	    	 
	    	 
	    	 
	    	 LinearLayout buttonplace= new LinearLayout(mContext);
	   		 buttonplace.setBackgroundResource(R.drawable.selector_xml_tab3);
	   		 buttonplace.setClickable(true);
	   		 buttonplace.setLayoutParams(firstinParams2);
	   		 buttonplace.setOrientation(LinearLayout.VERTICAL);
	   		 buttonplace.setGravity(Gravity.CENTER);

   		 
   		 
		     LinearLayout buttonperson= new LinearLayout(mContext); 
	   		 buttonperson.setBackgroundResource(R.drawable.selector_xml_tab3);
	   		 buttonperson.setClickable(true);
	   		 buttonperson.setLayoutParams(firstinParams);
	   		 buttonperson.setOrientation(LinearLayout.VERTICAL);
	   		 buttonperson.setGravity(Gravity.CENTER);

	

	   		 firstline.addView(textview);
	   		 firstline.addView(buttonplace);
	   		 firstline.addView(buttonperson);
   		 
	    	 
	    	 TextView type = new TextView(mContext);
	    	 type.setText("2014/5/1/11:17");
	    	 type.setTextSize(9);

	    	 
	    	 TextView place = new TextView(mContext);
	    	 place.setText("대구영재고");
	    	 place.setGravity(Gravity.CENTER);
	    	 place.setTextColor(0x45A0522D);

	    	 
	    	 TextView person = new TextView(mContext);
	    	 person.setText("박찬후만만만ㅅ세");
	    	 person.setGravity(Gravity.CENTER);

	    	 
	    	 
	    	 textview.addView(type);
	    	 buttonplace.addView(place);
	    	 buttonperson.addView(person);
	    	 
	    	 
	    	 
	    	 LinearLayout secondline = new LinearLayout(mContext);
	    	 secondline.setOrientation(LinearLayout.VERTICAL);
	    	 secondline.setLayoutParams(secondParams);
	    	 
	    	 
	    	 TextView textcontent = new TextView(mContext);
	    	 textcontent.setText("박박찬후는 박박찬후고 박박찬후이며 신종민은 신종민이고 신쫑짱이니라.");
	    	 textcontent.setTextSize(25);
	    	 textcontent.setGravity(Gravity.CENTER);
	    	 textcontent.setTextColor(0xCF000000);
	    	 
	    	 secondline.addView(textcontent);

	    	 
	    	 
	    	 
	    	 LinearLayout lastline = new LinearLayout(mContext);
	    	 lastline.setOrientation(LinearLayout.HORIZONTAL);
	    	 lastline.setLayoutParams(lastParams);
	    	 
	    	 
	 	    LinearLayout buttonreport = new LinearLayout(mContext); 
	   		 buttonreport.setBackgroundResource(R.drawable.selector_xml_tab2);
	   		 buttonreport.setClickable(true);
	   		 buttonreport.setLayoutParams(firstinParams);
	   		 buttonreport.setOrientation(LinearLayout.VERTICAL);
	   		 buttonreport.setGravity(Gravity.CENTER); 
	    	 
	 	    LinearLayout buttonreply = new LinearLayout(mContext); 
	   		 buttonreply.setBackgroundResource(R.drawable.selector_xml_tab2);
	   		 buttonreply.setClickable(true);
	   		 buttonreply.setLayoutParams(lastinParams);
	   		 buttonreply.setOrientation(LinearLayout.VERTICAL);
	   		 buttonreply.setGravity(Gravity.CENTER);
	   		 
	 	    LinearLayout buttonlike = new LinearLayout(mContext); 
	   		 buttonlike.setBackgroundResource(R.drawable.selector_xml_tab2);
	   		 buttonlike.setClickable(true);
	   		 buttonlike.setLayoutParams(firstinParams);
	   		 buttonlike.setOrientation(LinearLayout.VERTICAL);
	   		 buttonlike.setGravity(Gravity.CENTER);
	   		 
	   		 TextView reply = new TextView(mContext);
	    	 reply.setText("이  현수막에  낙서하기");
	    	 reply.setTextSize(15);
	    	 reply.setTextColor(0x65000000);
	    	 reply.setGravity(Gravity.CENTER);
	    	 
	   		 buttonreply.addView(reply);
	    	
	    	 lastline.addView(buttonreport);
	    	 lastline.addView(buttonreply);
	    	 lastline.addView(buttonlike);
	    	 
	    	 
	    	 

	    	 
	    	 actualbanner.addView(firstline);
	    	 actualbanner.addView(secondline);
	    	 actualbanner.addView(lastline);
	    	 
	 
	    	 vertiissue.addView(actualbanner);
	    		 
	    	 }

			
			
			return rootView;
		}
	}

}
